package iterator;

import constants.NumberConstants;
import data.Player;

public class TieIterativeBalance implements IterativeBalance {
	private Player [] players;
	private IterativeRanker iterativeRanker;
	private boolean print = false;
	public TieIterativeBalance(Player [] players, IterativeRanker iterativeRanker) {
		this.players = players;
		this.iterativeRanker = iterativeRanker;
	}

	@Override
	public void applyBalance() {
		addTiesAgainstEveryone(NumberConstants.NUM_OF_BALANCE_TIES);
//		minimumGames(PlayerDataGetter.getAverageNumberOfGamesPerOpponent(players));
		print = false;
	}
	
	private void addTiesAgainstEveryone(int numOfTies){
		for (int i = 0; i < players.length; i++)
			for (int j = i+1; j < players.length; j++)
				for (int k = 0; k < numOfTies; k++){
					if (print)
						System.out.println("fix: " + players[i] + " " + players[j]);
					iterativeRanker.applyTie(players[i], players[j], NumberConstants.FIX_WEIGHT);
				}
	}
//	private void minimumGames(double minGames){
//		for (int i = 0; i < players.length; i++)
//			for (int j = i+1; j < players.length; j++){
//				int numOfGames = 0;
//				List<Game> games = players[i].getOpponentToGameMap().get(players[j]);
//				if (games!=null)
//					numOfGames = games.size();
//				if (numOfGames>=minGames)
//					continue;
//				if (print)
//					System.out.println("balance: " + players[i] + " " + players[j] + " factor: " + (minGames-numOfGames));
//				iterativeRanker.applyTie(players[i], players[j],NumberConstants.BALANCE_WEIGHT*(minGames-numOfGames));
//			}
//	}
}
